package cn.bb.controller;

import cn.bb.model.Person;
import cn.bb.service.IPersonService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class ManagerController {
    @Resource
    private IPersonService personService;
    @RequestMapping("/index")
    public ModelAndView toIndexes(){
        return new ModelAndView("indexes");
    }
    @RequestMapping("/login")
    public String login(Person person, HttpSession session){
        int i = personService.adminLogin(person);
        if (i>0){
            session.setAttribute("username",person.getUsername());
            return "redirect:/index.do";
        }else{
            return "redirect:/login.html";
        }
    }
    public IPersonService getPersonService() {
        return personService;
    }
    public void setPersonService(IPersonService personService) {
        this.personService = personService;
    }

}
